// routes/user.js
const express = require("express");
const router = express.Router();
const handle = require("../routes_handle/user");
const { Response, CODE } = require("../utils/response");

// 微信手机号登录
router.post("/user/wxLogin", async (req, res, next) => {
  try {
    const result = await handle.wxLogin(req.body);
    res.json(Response.success(result, "登录成功"));
  } catch (err) {
    next(err);
  }
});

// 账号密码登录
router.post("/user/login", async (req, res, next) => {
  try {
    console.log("参数", req.body);
    
    const result = await handle.login(req.body);
    res.json(Response.success(result, "登录成功"));
  } catch (err) {
    next(err);
  }
});

// 获取用户信息
router.post("/user/info", async (req, res, next) => {
  try {
    const result = await handle.getUserInfo(req.body.userId);
    res.json(Response.success(result));
  } catch (err) {
    next(err);
  }
});

// 修改用户信息
router.post("/user/updateInfo", async (req, res, next) => {
  try {
    await handle.updateUserInfo(req.body);
    res.json(Response.success({}, "更新成功"));
  } catch (err) {
    next(err);
  }
});

module.exports = router;


